<?php
/**
 * Created by PhpStorm.
 * User: sunshubo
 * Date: 2017/11/22
 * Time: 22:08
 */

class Modify_student_model extends MY_Model
{
    function modify_student($body)
    {
//        type: phont name school grade class
//        var_dump($body);
        $body = json_decode($body);
        $type = $body->type;
        $value = $body->value;
        $id = $body->id;
        if ($type === 'phone') {
            if (strlen($value) <> 11) {
                return json_encode(array('result' => ERROR, 'msg' => '手机长度不足！', 'code' => '1001'));
            }
            $pass = substr($value, -6);
            $sql = "UPDATE ws_baseinfo SET phone = '$value',pass='$pass' WHERE id = $id";
            $query = $this->db->query($sql);
            if ($query) {
                return json_encode(array('result' => SUCCESS, 'msg' => '修改成功！'));
            }
        } elseif ($type === 'name') {
            $sql = "UPDATE ws_baseinfo SET name = '$value' WHERE id = $id";
            $query = $this->db->query($sql);
            if ($query) {
                return json_encode(array('result' => SUCCESS, 'msg' => '修改成功！'));
            }
        } elseif ($type === 'school') {

        }
        return json_encode(array('result' => ERROR, 'msg' => '修改失败！'));
    }
}